package classes;

import java.sql.*;
public class DbClass {
	private static Connection con = null;
	
	public static Connection startDb() throws ClassNotFoundException, SQLException{
		Connection connection;
		Class.forName("com.mysql.jdbc.Driver");    
		//Class.forName("org.gjt.mm.mysql.Driver");  
		//connection = DriverManager.getConnection("jdbc:mysql://pcgerosa.ime.usp.br:3306/sistemanoticia","noticiamac416","noticiamac416");
		connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sistemanoticia","root","");

		return connection;  
	} 
	 
	public static Connection getConnection() throws ClassNotFoundException, SQLException
	{
		if(con != null)
			return con;
		else{
			con = startDb();
			return con;
		}
	}
	
	public static void close() throws SQLException {
		con.close();
	}
}